<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
  <meta charset="utf-8">
  <title>学生成绩管理</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  <link rel="stylesheet" href="static/layui/css/layui.css" media="all">
  <link rel="stylesheet" href="static/layuiadmin/style/admin.css" media="all">
</head>
<body>
<!--templates/table/xscjgl-->
<div class="layui-card layadmin-header">
  <div class="layui-breadcrumb" lay-filter="breadcrumb">
  </div>
</div>

<div class="layui-fluid">
  <div class="layui-row layui-col-space15">
    <div class="layui-col-md12">
      <div class="layui-card">
        <div class="layui-card-header card-title">学生成绩管理</div>
        <div class="layui-card-body">
          <form class="layui-form" lay-filter="component-form-group" id="search_submits" onsubmit="return false">
            <div class="layui-form layui-card-header layuiadmin-card-header-auto" lay-filter="layadmin-useradmin-formlist">
                <div class="layui-inline">
                    <span class="agileits_grid">
                        <label  style="margin-left: 47px;margin-right: 20px">学期<i>:</i></label>
                        <div class="layui-input-inline">
                           <select name="sid" id="sid"></select>
                        </div>
                    </span>
                </div>
                <div class="layui-inline">
                    <span class="agileits_grid">
                        <label  style="margin-left: 47px;margin-right: 20px">课程<i>:</i></label>
                        <div class="layui-input-inline">
                           <select name="kid" id="kid"></select>
                        </div>
                    </span>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">学生学号：</label>
                    <div class="layui-input-inline">
                        <input type="number" class="layui-input" id="idcard" name="idcard" placeholder="请输入学生学号"  width="80px" min="0">
                    </div>
                </div>
                <div class="layui-inline">
                    <button class="layui-btn" lay-submit="search_submits" lay-filter="reloadlst_submit">查询</button>
                </div>
              <div class="layui-inline">
                <a class="layui-btn btn-add btn-default" id="btn-add">添加</a>
                <button type="button" class="layui-btn" id="improtbtn">导入数据</button>
                <a class="layui-btn btn-add btn-default" id="export">导出数据</a>
                <a class="layui-btn btn-add btn-default" id="downloadmb" href="static/CJIMPO.xlsx" download="成绩导入模板.xlsx">下载模板</a>
              </div>
            </div>
          </form>
          <table class="layui-hide" id="test-table-cellEdit" lay-filter="test-table-cellEdit"></table>
          <script type="text/html" id="test-table-operate-barDemo">
            <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
          </script>
        </div>
      </div>
    </div>
  </div>
</div>

<script src="static/layui/layui.js"></script>
<script th:inline="none">
  layui.config({
    base: 'static/layuiadmin/' //静态资源所在路径
  }).extend({
    index: 'lib/index' //主入口模块
  }).use(['index', 'table','form','upload'], function(){
    var $ = layui.$;
    var table = layui.table;
    var form = layui.form;
    var upload = layui.upload;
    var exportData;
    var loading = layer.load();
    var ins1 = table.render({
      elem: '#test-table-cellEdit'
      ,method:'post'
      , url: '/selectxscjgl'
      , cols: [[
        {field: 'st', title: '学生姓名', width:100, sort: true}
        , {field: 'sskid', title: '课程名称', width:100,sort:true}
        , {field: 'sssid', title: '学期', width:160,sort:true}
        , {field: 'grade', title: '成绩', width: 80, edit:'text',sort:true}
        , {field: 'xf', title: '学分', width: 80,sort:true}
        , {field: 'zxs', title: '总学时', width: 80,sort:true}
        , {field: 'khfs', title: '考核方式', width: 100,sort:true}
        , {field: 'ksxz', title: '考试性质', width: 100,sort:true}
        , {field: 'xfjd', title: '学分绩点', width: 100,sort:true}
        , {width: 178, align: 'center', fixed: 'right', toolbar: '#test-table-operate-barDemo'}
      ]]
      , done: function (res, curr, count) {
        layer.close(loading);
        exportData = res.data;
      }
    })
      form.on('submit(reloadlst_submit)', function (data) {
          var kid = $('#kid').val();
          var sid = $('#sid').val();
          var searchdata = data.field;
          var idcard = searchdata.idcard;
          ins1.reload({
              where:{
                  idcard:idcard,
                  kid:kid,
                  sid:sid
              }
          });
      })

    $("#export").click(function(){
      table.exportFile(ins1.config.id,exportData, 'xls');
    });
      $.ajax({
          url:"/selectxqxxgl",
          type:"post",
          dataType:"json",
          success: function (result) {
              var optionstring = "";
              optionstring ="<option value='' style='display: none'>"+"请选择"+"</option>";
              for (var j = 0; j < result.count; j++) {
                  optionstring += "<option value='" + result.data[j].id + "'>" + result.data[j].year+"--"+result.data[j].xq + "</option>";
              }
              $("#sid").html(optionstring);
              form.render('select');
          },
          error:function (e) {
              layer.msg('服务器错误',{icon:2});
          }
      });
      $.ajax({
          url:"/selectkcxxgl",
          type:"post",
          dataType:"json",
          success: function (result) {
              var optionstring = "<option value='' style='display: none'>"+"请选择"+"</option>";
              for (var j = 0; j < result.count; j++) {
                  optionstring += "<option value='" + result.data[j].id + "'>" + result.data[j].kname + "</option>";
              }
              $("#kid").html(optionstring);
              form.render('select');
          },
          error:function (e) {
              layer.msg('服务器错误',{icon:2});
          }
      });
    //监听单元格编辑
    table.on('edit(test-table-cellEdit)', function(obj){
      var value = obj.value //得到修改后的值
              ,data = obj.data //得到所在行所有键值
              ,field = obj.field; //得到修改内容的字段名称
      $.ajax({
        url:"/upxscjgl",
        data:{id:data.id , field:field,updateValue:value},
        type:"post",
        dataType:"json",
        success: function (result) {
          layer.msg('修改成功',{icon:1});
        },
        error:function (e) {
          layer.msg('修改失败',{icon:2});
        }
      })
    });
      upload.render({ //允许上传的文件后缀
          elem: '#improtbtn'
          ,url: '/importCJ'
          ,accept: 'file' //普通文件
          ,exts: 'xlsx|xls' //只允许上传压缩文件
          ,done: function(res){
              layer.msg(res.message);
          }
      });

    //监听工具条
    table.on('tool(test-table-cellEdit)', function(obj){
      var data = obj.data;
      if(obj.event === 'del'){
        layer.confirm('真的删除么', function(index){
          $.ajax({
            url:"/delxscjgl",
            data:{id:data.id},
            type:"post",
            dataType:"json",
            success: function (result) {
              layer.msg('已删除',{icon:1});
              obj.del();
            },
            error:function (e) {
              layer.msg('删除失败',{icon:2});
            }
          })
          layer.close(index);
        });
      }
    });
    $('#btn-add').on('click', function () {
      layer.open({
        type: 2,
        title: '录入成绩',
        maxmin: true,
        area: ['500px', '450px'],
        shadeClose: false, //点击遮罩关闭
        content: 'Jumpto?url=insert/xscjgl',
      });
    });
  });

</script>
</body>
</html>